package tokbox.com.opentok.util;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import tokbox.com.opentok.exception.OpenTokException;
public class TokBoxXML {
private transient Document xml;
public TokBoxXML(final String xmlString) throws OpenTokException{
try {
this.xml = TokBoxUtils.setupDocument(xmlString);
} catch(IOException ioe) {
throw new OpenTokException(ioe.toString());
} catch(ParserConfigurationException pce) {
throw new OpenTokException(pce.toString());
} catch(SAXException saxe) {
throw new OpenTokException(saxe.toString());
}
}
public boolean hasElement(final String elementName, final String parentElement) {
final Node parentNode = TokBoxUtils.parseXML(parentElement, this.xml.getElementsByTagName(parentElement));
if(parentNode == null) {
return false;
}
final Node searchNode = TokBoxUtils.parseXML(elementName, parentNode.getChildNodes());
return null != searchNode;
}
public String getElementValue(final String elementName, final String parentElement) {
final Node parentNode = TokBoxUtils.parseXML(parentElement, this.xml.getElementsByTagName(parentElement));
final Node searchNode = TokBoxUtils.parseXML(elementName, parentNode.getChildNodes());
return searchNode.getTextContent();
}
}